Having trouble with code

I’m having trouble figuring out why line 19 (t+=0.5;) is unreachable. Can somebody have a look, please?

static final int NUM_LINES = 10;

float t;

void setup() {

void draw() {
  translate(width/2, height/2);
  for (int i = 0; 1 < NUM_LINES; i++) {

float x1(float t){
  return sin(t/10) * 100 + sin(t/5) * 20;

float y1(float t){
  return cos(t/10) * 100;

float x2(float t){
  return sin(t/10) * 100 + sin(t) * 2;

float y2(float t){
  return cos(t/20) * 200 + cos(t/12) * 20;

First, your for loop is wacky. You want to be checking the value of i, but instead you’ve accidentally put 1

for (int i = 0; 1 < NUM_LINES; i++)
for (int i = 0; i < NUM_LINES; i++)

But that shouldn’t keep you from getting to the next line, it should just prevent the loop from running.

But that next line adds 0.5 to t. What does t equal before this? You never initialize it.


Hello, @Lolman223, and welcome to the Processing Foundation Forums!

You have this:

  for (int i = 0; 1 < NUM_LINES; i++) {

Due to the condition, 1 < NUM_LINES, it is an infinite loop.

1 Like

Thank you so much for your help

1 Like

DOH! I got my < and > mixed up

Hello, @richhelvey and welcome to the Processing Foundation Forums!

Yeah, with the condition corrected based on your observation, and with a proper initialization of t, the program will run, with all lines of code reachable, and with a nice animation to display.