We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › if statement
Page Index Toggle Pages: 1
if statement (Read 469 times)
if statement
Jul 2nd, 2006, 6:04am
 
ok, i'm tring to make a program that will plot a sequence of binary numbers. I want a square to show up for a one and nothing for a zero. i started workin on it but the if statement i recently added dosent seem to be working out. I have included to code. I want the if statement to execute if the variable = 1. and if not I want to pass over it. but it dosn't seem to be executing the statment at all. if any one could help it would be a great help.

I have marked the problem spot with a note.


size(500, 500);//setup
//primary loop
for (int counta=0; counta<5; counta=counta+1){
//formula to derive numeric sequence
int intcount = counta/15;
//create a string of binary value
String test = binary(intcount);

float dec = counta%15;  // Seperate the decimal
int dec2 = int(dec); //convert to dec
String decbin = binary(dec2); //place dec in string
//varable to controle number of sub loops
int limit = test.length();
//whole number draw
for (int count=0; count<limit; count=count+1){
char test1 = test.charAt(count);//count through string
print("test1:");
print(test1);
println(" ");

int limit2 = decbin.length();//dec loop amount

//dec draw
for (int count2=0;count2<limit2; count2=count2+1){
char testdec = decbin.charAt(count);//count through string
print("testdec:");
print(testdec);
println(" ");
int movea = count2*10;
int movedown = movea+100;
int moveb = counta*10;
int moveright = moveb+100;
println(moveright);
println(movedown);
if(testdec == 1){ //where i am having a problem.
fill(204,102,0);
rect(moveright,movedown,10,10);
println("square is drawn");
}
}
}
}
Re: if statement
Reply #1 - Jul 2nd, 2006, 10:17am
 
You're confusing integers and characters.

The integer value 1 is different to the character '1', so you need to change your test from testdec == 1 to testdec == '1'
Re: if statement
Reply #2 - Jul 2nd, 2006, 5:21pm
 
oops...

thanks a bunch.

I'm having a new problem that some one might be able to help with i'm sure it's realy simple and i'm new to processing so I havn't figured out all it's littel habbits yet.

I want the denominator in the fraction that is deriving my numeric sequence to be changing value based on a function. Every thing was working fine before  I added this capability.  I have included both the working and not working code in this post any help would be awsome.

just so you know it's suposed to draw a box depending on if the sequence shows a zero or a one.

NOT WORKING CODE

size(500, 2000);//setup
int start = 1;//number to start loop on
//primary loop
for (int counta=start; counta<200; counta=counta+1){
//formula to derive numeric sequence
int denominator = counta+5;
int intcount = counta/denominator;
println(denominator);
//create a string of binary value
String test = binary(intcount);

float dec = counta%denominator;  // Seperate the decimal
int dec2 = int(dec); //convert to dec
String decbin = binary(dec2); //place dec in string
println(decbin);
//varable to controle number of sub loops
int limit = test.length();
//whole number draw
for (int count=start; count<limit; count=count+1){
char test1 = test.charAt(count);//count through string
print("test1:");
print(test1);
println(" ");

int limit2 = decbin.length();//dec loop amount

//dec draw
for (int count2=start;count2<limit2; count2=count2+1){
char testdec = decbin.charAt(count2);//count through string
print("testdec:");
print(testdec);
println(" ");
int movea = count2*10;
int movedown = movea;
int moveb = counta*10;
int moveright = moveb;
println(moveright);
println(movedown);
if(testdec == '1'){ //where i am having a problem.
fill(204,102,0);
rect(movedown,moveright,10,10);
println("square is drawn");
}
if(testdec == '0'){
fill(153);
rect(movedown,moveright,10,10);
println("square is drawn");
}
}
}
}





WORKING CODE but no function for denominator

size(500, 2000);//setup
int start = 0;//number to start loop on
//primary loop
for (int counta=start; counta<200; counta=counta+1){
//formula to derive numeric sequence
int intcount = counta/13;
//create a string of binary value
String test = binary(intcount);

float dec = counta%13;  // Seperate the decimal
int dec2 = int(dec); //convert to dec
String decbin = binary(dec2); //place dec in string
println(decbin);
//varable to controle number of sub loops
int limit = test.length();
//whole number draw
for (int count=start; count<limit; count=count+1){
char test1 = test.charAt(count);//count through string
print("test1:");
print(test1);
println(" ");

int limit2 = decbin.length();//dec loop amount

//dec draw
for (int count2=start;count2<limit2; count2=count2+1){
char testdec = decbin.charAt(count2);//count through string
print("testdec:");
print(testdec);
println(" ");
int movea = count2*10;
int movedown = movea;
int moveb = counta*10;
int moveright = moveb;
println(moveright);
println(movedown);
if(testdec == '1'){ //where i am having a problem.
fill(204,102,0);
rect(movedown,moveright,10,10);
println("square is drawn");
}
if(testdec == '0'){
fill(153);
rect(movedown,moveright,10,10);
println("square is drawn");
}
}
}
}






Re: if statement
Reply #3 - Jul 3rd, 2006, 3:38am
 
thanks i've got it working
Page Index Toggle Pages: 1