List<int>list= new List<int>{1,2,3,4,5};//For Loop
for(int i =0; i <list.Count(); i++){ Console.WriteLine(list[i]);}//For Each Loop
foreach (int item inlist){ Console.WriteLine(item);}
# a 'while' loop runs until the condition is broken
a ="apple"while a =="apple":
a ="banana"# breaks loop as 'a' no longer equals 'apple'# a 'for' loop runs for the given number of iterations...for i inrange(10):print(i)# will print 0, 1, 2, 3, 4, 5, 6, 7, 8, 9# ... or through a sequence
array =[3,6,8,2,1]for number in array:print(number)# will print 3, 6, 8, 2, 1
list1 =[10,20,4,45,99]
mx=max(list1[0],list1[1])
secondmax=min(list1[0],list1[1])
n =len(list1)for i inrange(2,n):if list1[i]>mx:
secondmax=mx
mx=list1[i]elif list1[i]>secondmax and
mx != list1[i]:
secondmax=list1[i]print("Second highest number is : ",str(secondmax))
Output:-
Second highest number is:45