473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Initialising

thatos
105 100+
I have some variables which I just need for a certain loop, so I would like to ask is it better to initialise them inside a loop or before you enter a loop. I would like my algorithm to run faster.
Jul 17 '08 #1
4 1322
r035198x
13,262 8TB
Initializing them inside the loop means the initialization is done as many times as the loop is run.
Jul 17 '08 #2
thatos
105 100+
Initializing them inside the loop means the initialization is done as many times as the loop is run.
So it will be better to initialize them outside a loop?
Jul 17 '08 #3
r035198x
13,262 8TB
How about some more info?
What kind of loop are you using? for, while e.t.c
Are the initial values of the variables known before the loop is run?
Jul 17 '08 #4
JosAH
11,448 Expert 8TB
Also javap, the disassembler can give valuable information about the generated
code; it is part of Sun's jdk.

kind regards,

Jos
Jul 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ajit goel | last post by:
Hi; I have a question which respect to initialising and creating objects in loops.Here are the 2 scenarios: 1. ###############################################################################...
8
by: Nick Keighley | last post by:
Hi, is there a way of initialising a vector in a similar fashion to initialising an array? consider: Shape* triangle = new Triangle (); Shape* square = new Square (); Shape* shape_arr =...
8
by: nrhayyal | last post by:
hi all, is it a good idea to assign object to pointers without initialising it to NULL? suppose if i have a class TEST class ELEMENT { private: int a; string s1;
7
by: Mike P | last post by:
I have a class with a dozen+ properties, some of which will be set a value, and some not, depending on the constructor called. I also have a method which has only one overload and all of the...
6
by: Jeremy Targett | last post by:
Hello, I'm trying to initialise a two-dimensional array of characters, 12 by 60, with each entry maximum 6 characters wide. (It's a fix I'm making to an old program which I learned just enough C...
3
by: mark.bergman | last post by:
Running lint on code initialising a local 2-D array gives a warning. void f(void) { int a = { 0 }; ... lint gives "warning: Partially elided initialisation..." Should this be happening,...
107
by: DaveC | last post by:
I always used to initialise variables at declaration, then a couple of colleagues started telling me it was bad practice and that the compiler should be left to spot the use of uninitilised...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.