Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Sample Do While

Sample Do While

Example 26

Write the equivalent code for the following using for loop

var count=new Array();
i=0;
do
{
	if(i%2 == 0)
		count[i]=1;
	else
		count[i]= i *10;
	i=i+1;
}while(i<=5)
console.log(count);

Output

Example 27

Find the output

var sum, a;
sum = 0;
a = 1;
do
{
sum = sum + a;
a = a+2;
}while(a<=8)
console.log(sum);

Output

Loading

Views: 52

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments