0

[SOLVED] Pls will u say what is counter and when we have to use??and when we use max_index and what is it??

31st Mar 2020, 7:57 AM
Sai Revanth
Sai Revanth - avatar
3 Respostas
+ 3
Where did you read these? I can't say unless you show me the code. Also I recommend you to specify a relevant language in the thread tag, to improve context clarity 👍
31st Mar 2020, 8:35 AM
Ipang
+ 1
Words=["hello","world "] Counter=0 Max_index=Len (words)-1 While counter<=max_index: Word=words [counter] Print (word+"!") Counter=counter+1 I found it in iteration
31st Mar 2020, 8:40 AM
Sai Revanth
Sai Revanth - avatar
+ 1
Sai Revanth Counter is just a variable storing 0 value ,and max_index is storing the length of list,that is Max_index =Len(words)-1; =2-1=1 Now while counter<=max_index; Perform something Increase counter value Now counter value will become 1 and loop will run 2nd time(1<=1),loop has already run 1 time since 0<=1; Now again counter value will increase and loop won't run this time ,since it is 2<=1 which is false, So our Loop ran two times , Hopefully it helped you !I am not good at explanation but still, and you can take any variable name instead of counter and max_index but it will become a mess if you take some random names that have no meaning ,counter and max_index add some meaning to whatever is performed in this code ,
31st Mar 2020, 9:23 AM
Abhay
Abhay - avatar