Create variables with a loop? Jan25 '06

Feedback

# (1 of 9): Michael » bluetrait.com

49 minutes after the fact. (Wed 25 Jan 2006, 4:37 PM CST)

You should be able to do that. I needed to for one of the java things I was doing.

# (2 of 9): Josh » joahua.com/blog

2 hours, 33 minutes after the fact. (Wed 25 Jan 2006, 6:22 PM CST)

Sounds kinda-array-ish. Can't you just create the array then fill it up with as much stuff as you want? Or was that just the example that I kinda misconstrued?

Previous comment Return to entry

# (3 of 9): Michael » bluetrait.com

3 hours, 27 minutes after the fact. (Wed 25 Jan 2006, 7:16 PM CST)

The problem when adding things to an array, is with java you need to define the array size, and you're not sure how big this is going to be (for example, adding CDs to my java program, http://www.bluetrait.com/projects/dca/).

With PHP the array will just increase if needed. Java doesn't do this.

Previous comment Return to entry

# (4 of 9): Matthom

4 hours, 15 minutes after the fact. (Wed 25 Jan 2006, 8:03 PM CST)

An array would obviously make sense for storing multiple values, but I was thinking more along the lines of initializing variables in JavaScript, for use in manipulating the DOM.

So... with that for loop, not only could you initialize the variables, you could also do some basic initialization tasks, to each variable - provided it was the same for all variables.

Previous comment Return to entry

# (5 of 9): Tim » veryraw.com

4 hours, 27 minutes after the fact. (Wed 25 Jan 2006, 8:15 PM CST)

Sounds like a job for variable variables. Don't know if javascript can do it but php can. You make the value of a variable the variable. I don't know what the use of this would be. Sounds like you may be over thinking somethings. I'd be interested in seeing an application of this.

Previous comment Return to entry

# (6 of 9): Matthom

16 hours, 36 minutes after the fact. (Thu 26 Jan 2006, 8:25 AM CST)

Tim, yeah, that's kinda what I'm getting at. I looked at that link.. Wow.. gets pretty confusing. All those dollar signs and conversions - I bet it's hard to keep "straight," in the head.

Previous comment Return to entry

# (7 of 9): Jennifer Grucza » jennifergrucza.com

20 hours, 18 minutes after the fact. (Thu 26 Jan 2006, 12:07 PM CST)

This comment is for Michael:

The problem when adding things to an array, is with java you need to define the array size, and you're not sure how big this is going to be

If you need an array that can grow, why not just use a List? I use Lists ten times as much as I use arrays in Java. The Java Collections framework is enormously useful.

Previous comment Return to entry

# (8 of 9): Aaron M. Clay » Gamecopyworld.com

2 years, 2 months after the fact. (Tue 01 Apr 2008, 12:02 PM CST)

Use something along these lines:

import java.io.; import java.util.; //before the main class public static String variable_name;

//end of before main class FileOutputStream fout; try { fout = new FileOutputStream("variables.var"); int variables = new int(); for (int x =0;x<200;x++) { variablename = variablename +x; variables.add(variable_name);'

} for (int y =0;y

while (in.ready()) { String text = in.readLine(); System.out.println(text); }

catch (Exception ex1) { System.out.println ("Exception ex1 has occurred."); } }

From there, you can just grab the output from the file, or from the output your program just gave. It probably has a few syntax errors, but those are easily fixed.

Previous comment Return to entry

# (9 of 9): Aaron M. Clay » Gamecopyworld.com

2 years, 2 months after the fact. (Tue 01 Apr 2008, 12:02 PM CST)

Oh dear, the formatting was all lost...clean it up, and it should work decently

Previous comment Return to entry

RSS feed for comments on this post

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Return to entry.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Let’s say I want to quickly create five new variables, with a for loop...

You are at the feedback permalink page for: Create variables with a loop?

Read more...