python 3.x - Converting a for loop into a while loop -


i've done loop returns true if there 2 next 2 , i'm trying using while loop. can't seem make while loop work.

here's loop i've done

def has22(nums):     "return true if array contains 2 next 2 somewhere"""     in range(0, len(nums)-1):         if nums[i] == 2 , nums[i+1] == 2:             return true         return false 

i tried running while loop doesn't work.

def has22(nums):     """while loop version"""     = 0     while < len(nums) - 1:         if nums[i] == 2 , nums[i+1] == 2:         return true         += 1 

can please tell me what's wrong it?

  1. the return true not indented, it's returned (ie. not body of if statement)

  2. the function never returns `false

try:

def has22(nums):     """while loop version"""     = 0     while < len(nums) - 1:         if nums[i] == 2 , nums[i+1] == 2:             return true         += 1     return false 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -