Jump to content

IF in a loop


Guimly

Recommended Posts

<html><head><script type="text/javascript">var x=3</script><body><script type="text/javascript" src="created.js"></script></body></html>

Created.js:

document.write('<table border="1" style="position: absolute; right: 50%; top: 30%;">');for(i=1;i<7;i++)		{if(i==x){break};document.write('<tr><td>something</td></tr>');	}document.write('<tr><td>special TD</td></tr>');for(i=x;i<7;i++)		{document.write('<tr><td>something</td></tr>');	}  document.write('</table>');

So, isn't there a way to combine the two loops with the IF statement being inside and get 1 loop to do this entire work? I tried and did almost everything I thought of to make this work, and at the end this was my solution, yet I still wonder if there isn't the way I looked for - 1 loop with an IF statement inside that works correctly....Could someone pls repair these things for me so that I can see where I have been mistaken? Thanks in advance. PS: The code should be working as it is as well, yet it looks better when it's more compact :) And I want to keep the codes tidy and not messy :) Thanks all...

Link to comment
Share on other sites

Well, I was thinking of making 1 script with a menu that has the current page on it with a different background and not-clickable...Having the "x" variable changed in the head section of the different pages will help me doing it. This is not the final script, I will try making 2 arrays with URLs and stuff for each button and use the "x" thing again...Or something like that, I have the idea in my head :) The end idea as I said is to have 1 script and 1 menu with the menu being as interactive as possible for each page...

Link to comment
Share on other sites

document.write('<table border="1" style="position: absolute; right: 50%; top: 30%;">');for (i=0;i<=6;i++) {if (i==x) {document.write('<tr><td>special TD</td></tr>');}else {document.write('<tr><td>something</td></tr>');}}document.write('</table>');

Hm...the same code didn't really work when I made it :) Sad...That thing above was the goal, a friend of mine did it for a few secs....Strange indeed, I am 100% sure I tried this at least a thousend times - couldn't make it work...Nvm, sorry for the spam

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...