Drewyboyo Posted January 23, 2017 Share Posted January 23, 2017 How many ways can you write something to loop? We're writing a fixed repetition for graphics like, Reveal hidden contents int k;for (k = 1; k <=10; k++) Any cleaner ways to write this? Or something less monotonous? Quote Link to comment Share on other sites More sharing options...
Solution Posted January 23, 2017 Share Posted January 23, 2017 for (int k = 0; k < 10; K++) 2 Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted January 23, 2017 Share Posted January 23, 2017 Instead of declaring k above it, you could actually declare it in the loop itself as: for(int i = 0; i <= 10; i++){ // do stuff } 1 Quote Link to comment Share on other sites More sharing options...
Drewyboyo Posted January 23, 2017 Author Share Posted January 23, 2017 On 1/23/2017 at 4:48 PM, Solution said: for (int k = 0; k < 10; K++) isnt that exactly whats in my spoiler can't there be some silly "loop x" function On 1/23/2017 at 4:49 PM, Eagle Scripts said: Instead of declaring k above it, you could actually declare it in the loop itself as: for(int i = 0; i <= 10; i++){ // do stuff } thank ya Quote Link to comment Share on other sites More sharing options...
Solution Posted January 23, 2017 Share Posted January 23, 2017 On 1/23/2017 at 4:50 PM, Drewyboyo said: isnt that exactly whats in my spoiler can't there be some silly "loop x" function thank ya Nah you can create the int inside the for condition instead of above, same difference tho. a for loop is a loop x for (int index = 0; index < 10; index++) { //do stuff } Will loop 10 times. 1 Quote Link to comment Share on other sites More sharing options...
BoysNoize Posted January 23, 2017 Share Posted January 23, 2017 Check this out. Quote Link to comment Share on other sites More sharing options...
Hayase Posted January 23, 2017 Share Posted January 23, 2017 (edited) Who needs loops wen u can just switch it up int k= getWCExp(); //get ur wc exp cuz u need it switch (k) { case 1: checkWCexp();break; case 2: checkWCexp();break; case 3: checkWCexp();break; case 4: checkWCexp();break; case 5: checkWCexp();break; case 6: checkWCexp();break; case 7: checkWCexp();break; case 8: checkWCexp();break; case 9: checkWCexp();break; case 10: checkWCexp();break; default: checkWCexp();break; } np Edited January 23, 2017 by Hayase 1 Quote Link to comment Share on other sites More sharing options...
Drewyboyo Posted January 23, 2017 Author Share Posted January 23, 2017 Reveal hidden contents import java.awt.*;import java.applet.*;public class Lab07Bst extends Applet{public void paint(Graphics g){// Draw GridExpo.drawLine(g,250,0,250,650);Expo.drawLine(g,500,0,500,650);Expo.drawLine(g,750,0,750,650);Expo.drawLine(g,0,325,1000,325);int x1, y1, x2, y2, x, y, r;// Draw Red Horizontal LinesExpo.setColor(g,Expo.red);x1 = 0;y1 = 5;x2 = 250;y2 = 5;for (int k = 1; k <= 32; k++){Expo.drawLine(g,x1,y1,x2,y2);y1 += 10;y2 += 10;}int x3, y3, x4, y4;// Draw Blue Vertical LinesExpo.setColor(g,Expo.blue);x3 = 255;y3 = 0;x4 = 255;y4 = 325;for (int t = 1; t <= 25; t++){Expo.drawLine(g,x3,y3,x4,y4);x3 += 10;x4 += 10;}int x5, y5;// Draw Black Diagonal DotsExpo.setColor(g,Expo.black);x5 = 510;y5 = 280;for (int u = 1; u <= 24; u++){Expo.drawPoint(g,x5,y5);x5 += 10;y5 += -10;}int x6, y6, z6;// Draw Green Concentric CirclesExpo.setColor(g,Expo.green);x6 = 887;y6 = 170;z6 = 10;for (int i = 1; i <= 12; i++){Expo.drawCircle(g,x6,y6,z6);z6 += 10;}// Draw Purple Concentric Ovalsint x7, y7, z7, h7;Expo.setColor(g,Expo.purple);x7 = 125;y7 = 480;z7 = 5;h7 = 10;for (int i = 1; i <= 20; i++){Expo.drawOval(g,x7,y7,z7,h7);z7 += 4;h7 += 6;}// Draw Pink Concentric Arcsint x8, y8, z8, h8, g8, i8;Expo.setColor(g,Expo.pink);x8 = 260;y8 = 650;z8 = 5;h8 = 15;i8 = 0;g8 = 90;for (int i2 = 1; i2 <= 19; i2++){Expo.drawArc(g,x8,y8,z8,h8,i8,g8);z8 += 12;h8 += 16;}// Draw Brown Concentric Rectangles// Draw Gold Sphere On 1/23/2017 at 5:37 PM, Hayase said: Who needs loops wen u can just switch it up int k= getWCExp(); //get ur wc exp cuz u need it (switch k) { case 1: checkWCexp();break; case 2: checkWCexp();break; case 3: checkWCexp();break; case 4: checkWCexp();break; case 5: checkWCexp();break; case 6: checkWCexp();break; case 7: checkWCexp();break; case 8: checkWCexp();break; case 9: checkWCexp();break; case 10: checkWCexp();break; default: checkWCexp();break; } np Quote Link to comment Share on other sites More sharing options...
FrostBug Posted January 23, 2017 Share Posted January 23, 2017 If you're into this kinda stuff IntStream.range(0, 10).forEach(i -> System.out.println("Loop " + i)); Quote Link to comment Share on other sites More sharing options...
Drewyboyo Posted January 23, 2017 Author Share Posted January 23, 2017 On 1/23/2017 at 5:40 PM, FrostBug said: If you're into this kinda stuff IntStream.range(0, 10).forEach(i -> System.out.println("Loop " + i)); wheres frost godwards aio instead of replying to my starter java class help Quote Link to comment Share on other sites More sharing options...
FrostBug Posted January 23, 2017 Share Posted January 23, 2017 On 1/23/2017 at 5:41 PM, Drewyboyo said: wheres frost godwards aio instead of replying to my starter java class help 4giv 1 Quote Link to comment Share on other sites More sharing options...