vb.net - How to count and output total number of loops in visual basic console application? -


i learning visual basic , wrote simple visual basic console application "half or triple plus one" calculations , console app works count , display total number of loops run solution. here code:

sub main()     dim n double     console.writeline("enter starting number.")     n = console.readline()      while n <> 1          while n > 1              if n mod 2 = 0                 n = n / 2             else                 n = (n * 3) + 1              end if             console.writeline(n)         loop         if n = 1             console.writeline(             n = console.readline()         end if      loop        console.readline()  end sub 

i can't seem find counts , displays number of loops.

if i'm not misunderstanding you, problem solves introducing new variable named j, , final code results in

sub main() dim n double dim j integer console.writeline("enter starting number.") n = console.readline() j = 0  while n <> 1      while n > 1         'every time enter in cicle, "operation counter" increses 1         j = j + 1          if n mod 2 = 0             n = n / 2         else             n = (n * 3) + 1          end if         console.writeline(n)     loop     if n = 1         console.writeline(         n = console.readline()     end if  loop  console.writeline("i make " & j & " operations here!") console.readline()  end sub 

Comments