zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>,
	Ray Andrews <rayandrews@eastlink.ca>,
	 Zsh Users <zsh-users@zsh.org>
Subject: Re: for loop question
Date: Mon, 3 Nov 2014 02:53:48 +0100	[thread overview]
Message-ID: <CAHYJk3ThuftERfPB0k=MG2UV1+f4CgQ-7_x4d=8bKHUhUmU58A@mail.gmail.com> (raw)
In-Reply-To: <20141102213713.GA4412@chaz.gmail.com>

On Sun, Nov 2, 2014 at 10:37 PM, Stephane Chazelas
<stephane.chazelas@gmail.com> wrote:
> 2014-11-02 13:00:14 -0800, Bart Schaefer:
>> > I've fiddled around with various modifications but it seems to dislike "
>> [ -n "$TLC[i]" ] "
>> > even though the 'while' loop is happy with it.  That expression evaluates
>> to true or
>> > false, does it not? So why won't 'for' swallow it?
>>
>> The double parents (( )) are special arithmetic syntax.  You can't use an
>> ordinary shell command like "test" ( for which "[" is an alias) inside that
>> construct.
>
> You could with:
>
> for ((i=1; (z[$([ -n "$TLC[i]" ])0]),$? == 0; i++))
>   print -ru2 -- $TLC[i]
>
> (not that you would want to).
>
> Here, you more likely want:
>
> for i ("$TLC[@]") print -ru2 -- $i
>
> or
>
> print -rlu2 -- "$TLC[@]"
>
> or:
>
> for ((i = 1; i <= $#TLC; i++)) print -ru2 -- $TLC[i]
>
>
> Or (to print only till the first empty element):
>
> for ((i = 1; $#TLC[i]; i++)) print -ru2 -- "$TLC[i]"
>
> Or:
>
> print -rlu2 -- "${(@)TLC[1,TLC[(i)]-1]}"

We might want to avoid using obscure mixes of the discouraged
alternate syntax with syntax that depends on short_loops being set,
when helping people who are asking questions about basic syntax. :)

-- 
Mikael Magnusson


  parent reply	other threads:[~2014-11-03  1:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02 20:47 Ray Andrews
2014-11-02 21:00 ` Bart Schaefer
     [not found] ` <CAH+w=7aWS0xyS4CXRJBphDjesfUFQOsyJRMaG3RZRxmuj7xkOg__20885.3257158355$1414962125$gmane$org@mail.gmail.com>
2014-11-02 21:37   ` Stephane Chazelas
2014-11-02 22:44     ` Ray Andrews
2014-11-02 22:57       ` Bart Schaefer
2014-11-02 23:24       ` Oliver Kiddle
2014-11-03  0:07         ` Ray Andrews
2014-11-03  1:53     ` Mikael Magnusson [this message]
2014-11-03  2:22       ` Ray Andrews
2014-11-03  9:22         ` Mikael Magnusson
2014-11-03 17:26           ` Ray Andrews
2014-11-04  1:56     ` Han Pingtian
2014-11-04  2:29       ` Han Pingtian
2014-11-04  2:43       ` Bart Schaefer
2014-11-04  4:51         ` Han Pingtian
2014-11-04  6:37         ` Ray Andrews
2014-11-04  7:13           ` Bart Schaefer
2014-11-04 18:00             ` Ray Andrews
     [not found]       ` <141103184338.ZM32221__48957.5251042426$1415069142$gmane$org@torch.brasslantern.com>
2014-11-04  7:08         ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3ThuftERfPB0k=MG2UV1+f4CgQ-7_x4d=8bKHUhUmU58A@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).