f



Printing 2^1, 2^2, 2^3, 2^4 and 2^5

Hi,

When I use a while loop, the output is: 2 4 8 16 32, as desired:

<?php

$c=1;
while($c<=5) {
	$d = newpow(2, $c);
	print "$d ";
	$c++;
}

function newpow($base, $power) {
	// statements...
}
?>

The But when I use a for loop, the output is: 64:

<?php

for($c=1; $c<=5; $c++);
{
	$d = newpow(2, $c);
	print "$d ";
}

function newpow($base, $power) {
	// statements...
}
?>

Why is this??

Many thanks,

Michael
0
mejpark (19)
3/18/2008 10:59:16 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

3 Replies
2424 Views

Similar Articles

[PageSpeed] 15

mejpark wrote:
> When I use a while loop, the output is: 2 4 8 16 32, as desired:
[...]
> The But when I use a for loop, the output is: 64:
> 
> <?php
> 
> for($c=1; $c<=5; $c++);

Here your loop ended right at the ;

After the loop comes this:

> {
> 	$d = newpow(2, $c);
> 	print "$d ";
> }


Heiko

-- 
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/    Heiko Richler: Computer - Know How!
http://www.richler.info/  private Homepage
1
3/18/2008 11:02:19 AM
On 18 Mar, 11:02, Heiko Richler <heiko-rich...@nefkom.net> wrote:
> mejpark wrote:
> > When I use a while loop, the output is: 2 4 8 16 32, as desired:
> [...]
> > The But when I use a for loop, the output is: 64:
>
> > <?php
>
> > for($c=1; $c<=5; $c++);
>
> Here your loop ended right at the ;
>
> After the loop comes this:
>
> > {
> >    $d = newpow(2, $c);
> >    print "$d ";
> > }
>
> Heiko
>
> --http://portal.richler.de/Namensportal zu Richlerhttp://www.richler.de/   Heiko Richler: Computer - Know How!http://www.richler.info/ private Homepage

That's great, thanks.  I can't believe I didn't catch that!

Regards,

Mike
1
mejpark (19)
3/18/2008 11:10:01 AM
On 18 Mar, 11:02, Heiko Richler <heiko-rich...@nefkom.net> wrote:
> mejpark wrote:
> > When I use a while loop, the output is: 2 4 8 16 32, as desired:
> [...]
> > The But when I use a for loop, the output is: 64:
>
> > <?php
>
> > for($c=1; $c<=5; $c++);
>
> Here your loop ended right at the ;
>
> After the loop comes this:
>
> > {
> >    $d = newpow(2, $c);
> >    print "$d ";
> > }
>
> Heiko
>
> --http://portal.richler.de/Namensportal zu Richlerhttp://www.richler.de/   Heiko Richler: Computer - Know How!http://www.richler.info/ private Homepage

That's great, thanks.  I can't believe I didn't catch that!

Regards,

Mike
0
mejpark (19)
3/18/2008 11:10:17 AM
Reply:

Similar Artilces:

Does 4/2/2= (4/2)/2 =1 OR = 4/(2/2)=4
I don't have matlab and I am trying to translate some simple matlab code. Does 4/2/2 = (4/2)/2 = 1 or 4/2/2 = 4/(2/2) = 4 On 9/11/2012 9:43 AM, sarah.englander@gmail.com wrote: > I don't have matlab and I am trying to translate some simple matlab code. > > Does 4/2/2 = (4/2)/2 = 1 yes. At a given precedence level (and obviously two of the same operators are the same level) evaluation proceeds from LtoR. ....snip... <http://www.mathworks.com/help/techdoc/matlab_prog/f0-40063.html#f0-38155> -- dpb <none@non.net> wrote in message <k2njh1$jes$1@speranza.aioe.org>... > On 9/11/2012 9:43 AM, sarah.englander@gmail.com wrote: > > I don't have matlab and I am trying to translate some simple matlab code. > > > > Does 4/2/2 = (4/2)/2 = 1 > > yes. At a given precedence level (and obviously two of the same > operators are the same level) evaluation proceeds from LtoR. > > ...snip... > > <http://www.mathworks.com/help/techdoc/matlab_prog/f0-40063.html#f0-38155> > > -- There are a few thing you need to understand: 1. You need to get matlab in order to translate the simple code 2. You should define your parameters as in what is the expected output of your search based on the equations used: Is it : a) 4/2/2 b) (4/2/2) On 9/11/2012 11:13 PM, Salvinder wrote: .. > There are a few thing you need to understand: > 1. ...

2 * 2 * 2 * 2 or pow(2, 4)?
Hi , I hope this isn't too trivial to ask, but I'm evaluating a polynomial that involve lots of terms like x^2y^2z^3, and although I can use the power function pow(a, b), I wonder if just writing x*x*y*y*z*z*z for example wouldn't be more efficient than pow(x, 2)*pow(y, 2)*pow(z,3). Or is it all the same? Thanks, - Olumide Olumide wrote: > I hope this isn't too trivial to ask, but I'm evaluating a polynomial > that involve lots of terms like x^2y^2z^3, and although I can use the > power function pow(a, b), I wonder if just writing x*x*y*y*z*z*z for > exam...

linspace(2,2,2) returns [2 2] ??
May be the help for linspace should change? It says: "LINSPACE(X1, X2, N) generates N points between X1 and X2." Notice, it says BETWEEN. But when I ask for 2 points, between 2 and 2: ---------------- EDU>> linspace(2,2,2) ans = 2 2 --------------- May be mathematically this is ok? i.e. there are infinite points between the point and itself? (on the real line), but from programming point of view, it is confusing. no? --Nasser Maybe it should say "generates N points between X1 and X2, inclusive." What did you expect to get back as an answer from issuing linspace(2,2,2)? I didn't understand your statement "there are infinite points between the point and itself?" How do you have an infinite number of points between 2 and 2? I can see an infinite number of points between 2 and something that's not itself, like 2.00000000000000001, but if they are absolutely perfectly identical how are you getting an infinite number of points? On 10/10/2010 11:16 AM, Image Analyst wrote: > Maybe it should say "generates N points between X1 and X2, inclusive." > > What did you expect to get back as an answer from issuing linspace(2,2,2)? > I was just not expecting it to "work". may be an error message. That is not the point. The point is that it did work. > I didn't understand your statement "there are infinite points between the point and it...

[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 3;....;n n n n n]
Hi, Anybody knows how to create this matrix but without using any loops? a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ] Thank you. Hana. Hana wrote: > Hi, > Anybody knows how to create this matrix but without using any loops? > a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ] HELP REPMAT - Randy Hana wrote: > > > Hi, > Anybody knows how to create this matrix but without using any > loops? > a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ] > > Thank you. > Hana. Hope this isn't homework. >> repmat([1:n]'...

ANN: ActivePython 2.6.2.2, 3.1.0b1.0, 2.5.4.4 is now available
I'm happy to announce that ActivePython 2.6.2.2, 3.1.0b1.0 and 2.5.4.4 are now available for download from: http://www.activestate.com/activepython/ This is a patch release that updates ActivePython to core Python 2.6.2 and 3.1b2. This release also contains updates to Tcl/Tk 8.5.7 and Tix 8.4.3. We recommend that you try 2.6 version first. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X,...

OSK 2.0, 2.2 and 2.3
Does anyone here have any of the versions named in the subject? I am unravelling 68K Basic I-Code, and I need to compare 2.0, 2.2 and 2.3 modules with 2.1 and 2.4 modules. There are differences between 2.1 and 2.4, and I want to know how many other differences there are between versions. Thanks in advance. Wayne Campbell ...

Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2
I've been tasked with upgrading the JVM from 1.3 to 1.4, and the third party libraries used by my company on our existing Java framework. I'm most worried about any problems that may occur due to upgrading Xalan and Xerces as our framework performs much XML transformation and processing. Does anyone have a link to known issues with such an upgrade (besides the Xalan / Xerces sites) ? Or has anyone done such an upgrade and can share their pearls of wisdom? Thanks Chris ...

wxPython 2.4.2.4 segmentation fault on (Python 2.2.2 SuSE 8.2)
Hi everything runs normally but exiting demo.py or any app we get Segmentation Fault wxPython was built from sources (as per readme.1st.txt) as latest downloaded from wxPython site while building wxGTK several errors reported as could not read from makefile.in files please assist Sanjay Minni Note that we used GTK1 i.e. compiled without the GTK2 option on SuSE 8.2 Thanks Sanjay Minni ...

LaTex equation numbering like 2.1, 2.2, also 2.0.1, 2.0,2, 2.1.1, etc
David Roach wrote: > Is there a simple command to have latex number > the equations by the section numbers automatically. > > David From the LaTeX Companion (what a wonderful book!) %%%%%%%%%%%%%%%%%%%%%% % number equations within sections % In preamble \makeatletter \@addtoreset{equation}{section} \makeatother \renewcommand{\theequation}{\thesection.\arabic{equation}} %%%%%%%%%%%%%%%%%%%%%% Numbers within sections...I use this all the time in articles. Even works with ******************* ******************* Brilliant. And then I got numbering within subsections by repeating and editing (not replacing), so I now have:- (Just after the documentClass command) \makeatletter \@addtoreset{equation}{section} \makeatother \renewcommand{\theequation}{\thesection.\arabic{equation}} \makeatletter \@addtoreset{equation}{subsection} \makeatother \renewcommand{\theequation}{\thesubsection.\arabic{equation}} Bob Bob Marlow schrieb: > David Roach wrote: > >> Is there a simple command to have latex number >> the equations by the section numbers automatically. >> >> David > > From the LaTeX Companion (what a wonderful book!) > > %%%%%%%%%%%%%%%%%%%%%% > > % number equations within sections > % In preamble > > \makeatletter > \@addtoreset{equation}{section} > \makeatother > \renewcommand{\theequation}{\thesection.\arabic{equation}} > > %%%%%%%%%%%%%%%%%%%%%% [more code] > Hi! I th...

Newbie question; why (cons (list 1 2) (list 3 4)) is ((1 2) 3 4) and not ((1 2) (3 4))
Hi, I just started to learn LISP, and stumbled in SICP upon (cons (list 1 2) (list 3 4)) is evaluated to ((1 2) 3 4) I do not understand why this is not: ((1 2) (3 4)) because (cdr (cons (list 1 2) (list 3 4))) is (3 4) and (car (cons (list 1 2) (list 3 4))) is (1 2) Is there a logical explanation? Thank you for your patience. -- Greg Out of order, gregor <gregor@ediwo.com> writes: > Is there a logical explanation? Yes. > I just started to learn LISP, and stumbled in SICP upon But first, let's talk about LISP, Lisp, Scheme and Common Lisp. LISP is the name of the programming language invented in 1959 by John McCarthy and of the first program implementing it written amongst other by Steve Russel, one of his students. LISP 1.5 is a segueing version of that same program dating about 1962 that had some distribution. Then various lisp languages were developed at various places by various teams. Names such as MacLisp, InterLisp, LeLisp, StandardLisp, vLisp, Lisp Machine Lisp, Scheme, GNU Emacs Lisp, etc. It was quite a mess, and people had a hard time sharing programs. So they talked and designed and wrote and voted and produced the ANSI Common Lisp standard (in the USA), meanwhile in Europe they produced the ISO Lisp standard. Nowadays, almost all the other lisps are "dead", with only scheme (current version r5rs, r7r...

MIME encoding change in Python 2.4.3 (or 2.4.2? 2.4.1?)
I have an application that processes MIME messages. It reads a message from a file, looks for a text/html and text/plain parts in it, performs some processing on these parts, and outputs the new message. Ever since I recently upgraded my Python to 2.4.3, the output messages started to come out garbled, as a block of junk characters. I traced the problem back to a few lines that were removed from the email package: The new Python no longer encodes the payload when converting the MIME message to a string. Since my program must work on several computers, each having a different version of Pyth...

Concurrent usage of glibc 2.2.4 and 2.3.2
I'm trying to run applications that need glibc 2.2.4 in a Linux (formerly RH 7.2, but kernel + most apps + gcc + glibc updated) box whose current glibc is 2.3.2 (obtained from Fedora's glibc-2.3.2-101.4.i386.rpm). I have several questions where I'd appreciate some help. - checking the version definitions for both runtime loaders (RTLs, or ld-linux.so), I see that: - both RTLs define ld-linux.so.2, GLIBC_2.0, GLIBC_2.1 - ld-2.2.4.so defines versions GLIBC_2.1.1, GLIBC_2.2, GLIBC_2.2.3, which ld-2.3.2.so does not - ld-2.3.2.so defines GLIBC_PRIVATE and GLI...

VIBE 2.2 #2
About: Visual Information Broker Enterprise (VIBE) is an IDE that enables application developers to automate the design and development of infrastructure components for complex distributed cross-platform, cross-language systems applications. You can define messages and generate infrastructure support code for the IBM MQ information bus, Sybase, Microsoft SQL Server, Oracle, and other JDBC compliant databases, XML with transformations that use tools like XSL, and J2EE. It also includes a fully functional Business Rules engine, along with a graphical programming environment. Changes: This relea...

OTM 2.2 #2
Hi all Just installed OTM on a cust pc (Win XP) Got a problem that when using the system terminal to access Meridian Mail, I am unable to exit from mail as the Cntrl ] function is not recognised. Now is this a problem with OTM or with the customers PC? Thanks Solved it. The term type was set to VT100 and not VT220 ...

how to "(1-3*x^2)/(1-3*x+x^2+2*x^3) => 1/(1-2*x) + x/(1-x-x^2)"?
hi normal(1/(1-2*x) + x/ (1-x-x^2),expanded); 1/(1-2*x) + x/(1-x-x^2) => (1-3*x^2)/(1-3*x+x^2+2*x^3) how to do the reverse? dillogimp@gmail.com writes: > normal(1/(1-2*x) + x/ (1-x-x^2),expanded); > 1/(1-2*x) + x/(1-x-x^2) => (1-3*x^2)/(1-3*x+x^2+2*x^3) > how to do the reverse? convert(%,parfrac,x); -- Joe Riel ...

x^(3/2)+x^(5/2) = (x+x^2)*x^(1/2)
Is there a simple way to get Maple to convert x^(3/2) + x^(5/2) to (x+x^2)*x^(1/2). I am willing to assume(x>0). Maple does recognize these as being equal: > p:=x^(3/2)+x^(5/2): > q:=(x+x^2)*sqrt(x): > simplify(p-q); 0 Here's a clumsy way to do it: > p:=x^(3/2)+x^(5/2): > assume(t>0): > subs(x=t^2,p); > simplify(%,{t^2=x}); > collect(%,t); Is there something simpler? (This has undoubtedly come up before, but I cannot find it anywhere.) --Edwin If you do not insist upon your incomplete factoriz...

wxGTK 2.4.2 issues (GTK 2.2.4)
Hello all, I tried the first time my wxMSW application on Linux with wxGTK and I experienced following issues und would like to know if it is a GTK limitation or wx' one: - Loading .xpm - files in .xrc - resources doesn't work (no handler) But perhaps in a toolbar wxBitmap("myIcon_16.xpm") works. - No "real" MDI support and no StatusBar support for Childframes (this _should_ be documented) - wxTE_RIGHT does not work for wxTextCtrl - wxListCtrl in wxLC_ICON - Style aligns the icons to the left. I know that's a Win32-Feature to align the icons "centre" but Evolution also supports this (perhaps Gnome feature?) Thanks, Michael Forstner --------------------------------------------------------------------- Please read http://www.wxwindows.org/mlhowto.htm before posting. To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwindows.org For additional commands, e-mail: wx-users-help@lists.wxwindows.org ...

Upgrading 2.4.1 to 2.4.2
Hi, I have Python 2.4.1 and have downloaded 2.4.2. Is there a way to avoid installing everything and, instead, just upgrade? Thanks, Sorin __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com Sori Schwimmer wrote: > I have Python 2.4.1 and have downloaded 2.4.2. Is > there a way to avoid installing everything and, > instead, just upgrade? Run the following code on your 2.4.1 installation and post the results: python -m platform Or, if you prefer: import platform platform.platform(True, False) -- -Scott D...

Apache 2.2.2 and PHP 5.1.4 on Win2k crashing
I just installed Apache 2.2.2 on my Windows 2000 (SP4) machine to test the new version. Everything works except PHP (version 5.1.4): when starting Apache, it pops out a message saying that it is unable to locate the module (even set on the correct path!), stops the execution and exits. On the other side, PHP works fine with Apache 2.0.55, so It's not a problem of a broken build. Got ideas? Thanks. -- Massimo Lombardo unwiredbrain@gmail.com wrote: > I just installed Apache 2.2.2 on my Windows 2000 (SP4) machine to test > the new version. > Everything works except PHP (version ...

2 + 2 =
2 + 2 = 4. Period. The above was posted as a test. I am seeing if people in csma will start to debate the accuracy of my claims. After all, in base 3, there is no symbol "4". I am sure others can come up with ways to show I am wrong. Then, when I explain how 2 + 2 really is equal to 4, even in other bases or whatever other silliness is presented, I will be told that I am changing my claim. Someone will even go so far as to say that since I admit there is no "4" in base 3, that my argument has been refuted, and I should no longer state that 2 + 2 = 4. This has only been a test. Snit wrote: > 2 + 2 ...

2 or not 2
is this a question! http://members.iinet.net.au/~moussa/Image029.jpg Should I? the in house auction is tomorrow :-/ Moussa -- The information contained in this post is copyright of the poster, and specifically may not be published in, or used by http://www.jlaforums.com Il Wed, 09 Sep 2009 16:13:08 +0800, Cheers ha scritto: > is this a question! > > http://members.iinet.net.au/~moussa/Image029.jpg > > Should I? the in house auction is tomorrow :-/ > > Moussa I don't know it but it's BIG ! Do you have free space ? How much, do you think, it will cost ? Could be a nice addiction, but let's listen to someone else... On Sep 9, 4:13 am, Cheers <moussa...@hotmail.com> wrote: > http://members.iinet.net.au/~moussa/Image029.jpg Personally, I'm not that fond of Sun equipment, so I haven't paid that much attention to their offerings. My guess is that the rack is a storage array, and it appears to be on the old side, so it's likely that the total storage capacity in the array could be met or exceeded by one large SATA drive (both 1.5TB and 2.0TB 3.5-inch drives are currently available) -- at much lower noise and power levels. Of course, if you already had one of these bad boys and were just looking for an inexpensive source of spare parts, I'd say go for it. Rick Ekblaw Hi Moussa ! > is this a question! > > http://members.iinet.net.au/~moussa/Image029.jp...

glibc 2.2.5 vs 2.3.2 on RH Enterprise
All executables on our development machine runnin RH Enterprise with glibc 2.2.5 are compiled statically. When we installed Enterprise 3 on our test machine all executables as one started to crash with this stack: (gdb) where #0 0x080a67a1 in _dl_relocate_object () #1 0x0808d6b3 in dl_open_worker () #2 0x0808c28f in _dl_catch_error () #3 0x0808d8a7 in _dl_open () #4 0x080697ca in do_dlopen () #5 0x0808c28f in _dl_catch_error () #6 0x080696bd in __libc_dlopen () #7 0x08067dd6 in __nss_lookup_function () #8 0x0806845e in __nss_lookup () #9 0x08068657 in __nss_passwd_loo...

[MSW 2.4.2 and 2.5.2] wxComboBox event bug?
Hi, I have a fairly concise example program appended below where selecting a wxComboBox item results in two EVT_COMBOBOX events being called, both in 2.4.2 and 2.5.2. The same application seems to work correctly on Mac OSX wxWidgets 2.4.2. I saw some discussion of this in the list archives but didn't see any resolution. Is this a known bug or am I doing something obviously wrong here? Thanks much, -Hollister -------------------------------------------- #include <wx/wx.h> class HelloWorldApp : public wxApp { public: virtual bool OnInit(); }; DECLA...

ANN: ActivePython 2.5.2.2 and 2.4.5.14 are now available
I'm happy to announce that ActivePython 2.5.2.2 and 2.4.5.14 are now available for download from: http://www.activestate.com/products/activepython/ These are patch releases that update ActivePython to core Python 2.5.2 and 2.4.5. What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available. ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3, ActivePython 2.5 only) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing (ActivePython 2.5 only), ctypes (on supported platforms, ActivePython 2.5 only) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. See this page for full details: http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found...

Web resources about - Printing 2^1, 2^2, 2^3, 2^4 and 2^5 - comp.lang.php

Printing - Wikipedia, the free encyclopedia
This article is about the process of reproducing text and images. For the handwriting method often called printing, see block letters . For other ...

Help Mr Plumbum sort his printing box in this matching game
... path in Linken, an elegant puzzler or Meteors are falling, dont get squished in Danger Dodgers . Mr Plumbum Help Mr Plumbum sort his printing ...

Injured toucan gets beak repair courtesy of 3D printing
A custom prosthetic beak-piece helps a toucan rescued from animal smugglers eat and groom normally once again. 3D printing isn't just for people ...

Europe To Use 3D Printing To Build Permanent Moon Base By 2030
Europe To Use 3D Printing To Build Permanent Moon Base By 2030

Tokyo students develop architectural 3D-printing pen
A group of University of Tokyo students overseen by architect Kengo Kuma have developed a 3D-printing pen that can be used to create complex ...

MakerBot learns that 3D printing and copyright don't quite mix
Trying to stop unauthorized 3D printing is like plugging a hole in a dam with your finger once the template for an object leaks out, it's virtually ...

3D Printing Your Own Braces Works, Is a Terrible Idea
At the age of nine, I became the first kid in my elementary school class to get braces. They did their job, but by the time I left college, I’d ...

Getting it Right by Getting it Wrong: RepRap and the Evolution of 3D Printing
The beginning of the DIY 3D printing movement was a heady time. There was a vision of a post-scarcity world in which everything could and would ...

3-D Printing: Gigi The Macaw Gets First-Ever Titanium Prosthetic Beak (PHOTOS)
Gigi the macaw is the first-ever recipient of the world's first 3-D-printed titanium beak.

Archinaut, A 3D Printing Robot To Make Big Structures In Space
Historically, the only way to get anything into orbit has been by rocket; a process that is massively expensive, cumbersome, and presents a slew ...

Resources last updated: 3/23/2016 6:35:27 PM