The Gateway to Computer Science Excellence
0 votes
 for( i = n, j = 0; i > 0; i /= 2, j +=i )

Why There is no condition check for j here

in Algorithms by (243 points) | 69 views

you can declare as  many variables in for as you want. You will check conditions based on your requirement. Here the writer might not want j to act as a control variable governing the number of  times loop runs so he didnt apply any condition check which indeed is perfectly normal.

Here loop control variable is “i” , i will stop after logn times . In that time j will increase upto logn.
I am not getting how this loop will execute

Pls give one example for any value of n

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,297 answers
104,978 users