java - FOR loops in BlueJ -


i have code , works not on different created worlds cause length different how can fix this? bit stuck

void moverobot(){     for(int x=1; x<=61; x++) {         if(isspaceinfrontofrobotclear()) {             moverobotforwards();         }         else {             turnrobotleft();             turnrobotleft();             turnrobotleft();         }     } } 

by passing in length of world parameter, , using instead of 61. example:

void moverobot (int worldsize){     for(int x=1; x<=worldsize; x++) {         if(isspaceinfrontofrobotclear()) {         moverobotforwards();         }         else {             turnrobotleft();             turnrobotleft();             turnrobotleft();         }      }  } 

alternatively, if problem in moverobotforwards, moverobotforwards needs made aware of world's size in similar fashion.


Comments